import React, { Component } from 'react'
import Context from '../../utils/context'
import { Switch, Route, Redirect } from 'react-router-dom'
export default class Alert2 extends Component {
    state = { typeIndex: 0 }
    static contextType = Context;
    render() {
        let { n, closeAlert1, addN, disN } = this.context
        return (
            <div className='alert1'>
                <div className='con'>
                    <h1 onClick={closeAlert1}>关闭</h1>
                    <div>
                        <button onClick={this.add}>+</button>
                        <button>{n}</button>
                        <button onClick={this.dis}>-</button>
                    </div>
                    <div><button onClick={this.addCar1}>加入购物车</button></div>
                </div>
            </div>
        )
    }
    add = () => {
        this.context.addN()
    }
    dis = () => {
        if (this.context.n > 0) {
            this.context.dis()
        }
    }
    addCar1 = () => {
        // this.props.history.push('/car')
        <Switch>
                {
                    props.routes.map(item=>{
                        return (
                            <Route key={item.path} path={item.path} component={()=>{
                                if(item.meta.isAuth&&!sessionStorage.getItem('token')){
                                    return <Redirect to='/login'></Redirect>
                                }
                                return <item.component routes={item.children}></item.component>
                            }}></Route>
                        )
                    })
                }
                <Redirect exact from='/' to='/layout/home'></Redirect>
                <Redirect exact from='/layout/my' to='/layout/my/part1'></Redirect>
            </Switch>

    }
}
